﻿using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;

// Designer support 
using System.Drawing;
using System.Web.UI.Design;

namespace Medianamik.UI.Controls
{
    /// <summary>
    /// Mirror control.
    /// Duplicates the rendered Html of another control on the page.
    /// </summary>
    [ToolboxData("<{0}:Mirror runat=server></{0}:Mirror>")]
    public class Mirror : WebControl
    {
        //public string ControlID = null;

        //#region METHODS

        //protected override void Render(HtmlTextWriter writer)
        //{
        //    // Ensure that the ControlID was defined
        //    // otherwise abort the render
        //    if (ControlID == null)
        //        return;

        //    // Locate the control identified by ControlID
        //    Control c = Parent.FindControl(ControlID);

        //    // If the specified control was not found, abort
        //    if (c == null)
        //        return;

        //    // Call the control's Render function in order to
        //    // generate the Mirror control's HTML.
        //    // This, in a nutshell is the mirroring process.
        //    c.RenderControl(writer);
        //}

        //#endregion

        protected override void OnPreRender(EventArgs e)
        {
            if (!ScriptManager.GetCurrent(this.Page).IsInAsyncPostBack)
            {
                string jsMirror = Medianamik.Core.Sugar.Resources.GetResourceText("Controls.Mirror.mirror.js", this.GetType().Assembly);

                if (!string.IsNullOrEmpty(jsMirror))
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "jsMirror", jsMirror, true);
                }
            }

            base.OnPreRender(e);
        }
    }
}
